<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教务管理系统 - 我的选课</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .header {
            background-color: #1976d2;
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .header h2 img {
            height: 36px;
            margin-right: 10px;
        }

        .header .breadcrumb {
            margin: 0;
            background: transparent;
            color: white;
        }

        .header .breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }

        .header .breadcrumb a:hover {
            color: white;
        }

        .header .breadcrumb-item.active {
            color: white;
        }

        .header .breadcrumb-item+.breadcrumb-item::before {
            color: rgba(255,255,255,0.6);
        }

        /* 侧边栏样式 */
        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            bottom: 0;
            width: 250px;
            background-color: white;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            overflow-y: auto;
            z-index: 100;
            padding-top: 20px;
        }

        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar-menu > li {
            margin-bottom: 5px;
        }

        .sidebar-menu > li > a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: #333;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .sidebar-menu > li > a:hover {
            background-color: #f0f0f0;
            border-left-color: #1976d2;
        }

        .sidebar-menu > li > a.active {
            background-color: #e3f2fd;
            border-left-color: #1976d2;
            color: #1976d2;
        }

        .sidebar-menu > li > a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
        }

        .sidebar-submenu {
            list-style: none;
            padding-left: 53px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease, padding 0.3s ease;
        }

        .sidebar-menu > li.open .sidebar-submenu {
            max-height: 500px;
            padding-bottom: 10px;
        }

        .sidebar-submenu > li > a {
            display: block;
            padding: 8px 0;
            color: #666;
            text-decoration: none;
            transition: all 0.3s;
        }

        .sidebar-submenu > li > a:hover {
            color: #1976d2;
        }

        .sidebar-submenu > li > a.active {
            color: #1976d2;
            font-weight: 500;
        }

        /* 确保图标旋转 */
        .sidebar-menu > li.open .has-submenu .bi-chevron-down {
            transform: rotate(180deg);
            transition: transform 0.3s ease;
        }

        .has-submenu .bi-chevron-down {
            transition: transform 0.3s ease;
        }

        /* 内容区样式 */
        .content {
            margin-left: 250px;
            padding: 76px 20px 20px;
        }

        /* 用户名下拉菜单样式 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
            cursor: pointer;
            padding: 8px 12px;
            border-radius: 8px;
            transition: all 0.2s ease;
        }
        .header-user:hover {
            background-color: rgba(255,255,255,0.1);
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
            border: 2px solid rgba(255,255,255,0.3);
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            color: white;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown::before {
            content: '';
            position: absolute;
            top: -6px;
            right: 20px;
            width: 12px;
            height: 12px;
            background: #fff;
            transform: rotate(45deg);
            box-shadow: -2px -2px 4px rgba(0,0,0,0.1);
        }
        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background: #f8f9fa;
            color: #2196f3;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        .card {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 2px 20px rgba(0,0,0,0.08);
            margin-bottom: 20px;
            overflow: hidden;
        }

        .card-header {
            background: #ffffff;
            color: #333333;
            padding: 20px;
            border: none;
            border-bottom: 1px solid #dee2e6;
        }

        .card-header h5 {
            margin: 0;
            font-size: 1.2rem;
            font-weight: 600;
        }

        .card-body {
            padding: 20px;
        }

        .search-bar {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 20px;
        }

        .search-bar input {
            border-radius: 8px;
            border: 1px solid #dee2e6;
            padding: 8px 12px;
            font-size: 1rem;
            width: 250px;
        }

        .search-bar .btn {
            border-radius: 8px;
            padding: 8px 16px;
        }

        .table {
            margin-bottom: 0;
            background: white;
        }

        .table th {
            background-color: #f8f9fa;
            border-top: none;
            font-weight: 600;
            color: #495057;
            text-align: center;
            padding: 15px 10px;
            border-bottom: 2px solid #dee2e6;
        }

        .table td {
            text-align: center;
            padding: 15px 10px;
            vertical-align: middle;
            border-bottom: 1px solid #dee2e6;
        }

        .table-hover tbody tr:hover {
            background-color: rgba(25,118,210,0.05);
        }

        .status-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 500;
        }

        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }

        .status-approved {
            background-color: #d4edda;
            color: #155724;
        }

        .status-rejected {
            background-color: #f8d7da;
            color: #721c24;
        }

        .btn-danger {
            background-color: #dc3545;
            border-color: #dc3545;
        }

        .btn-danger:hover {
            background-color: #c82333;
            border-color: #bd2130;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            margin-bottom: 20px;
            color: #dee2e6;
        }

        .pagination {
            margin: 20px 0 0 0;
            justify-content: center;
        }

        .pagination .page-link {
            border: 1px solid #dee2e6;
            color: #495057;
            border-radius: 6px;
            margin: 0 2px;
        }

        .pagination .page-item.active .page-link {
            background: linear-gradient(135deg, #1976d2 0%, #42a5f5 100%);
            border-color: #1976d2;
        }

        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s;
            }

            .sidebar.active {
                transform: translateX(0);
            }

            .content {
                margin-left: 0;
            }
        }

        /* 评教星级评分样式 */
        .rating-stars {
            font-size: 1.5rem;
            cursor: pointer;
        }

        .rating-stars i {
            color: #ddd;
            transition: color 0.2s;
            margin-right: 2px;
        }

        .rating-stars i.active {
            color: #ffc107;
        }

        .rating-stars i:hover {
            color: #ffc107;
        }

        .rating-text {
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
<!-- 头部导航栏 -->
<div class="header">
    <div class="header-left">
        <h2><img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo"> 教务管理系统</h2>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/student/home">首页</a></li>
                <li class="breadcrumb-item"><a href="#">教学管理</a></li>
                <li class="breadcrumb-item active">我的选课</li>
            </ol>
        </nav>
    </div>

    <!-- 用户下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户头像" id="userAvatar">
        <span class="header-user-name" id="userName">
            <c:choose>
                <c:when test="${not empty currentStudent and not empty currentStudent.user and not empty currentStudent.user.realName}">
                    ${currentStudent.user.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                    ${sessionScope.loggedInUser.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                    ${sessionScope.loggedInUser.username}
                </c:when>
                <c:otherwise>
                    学生
                </c:otherwise>
            </c:choose>
        </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                个人信息
            </a>
            <a href="${pageContext.request.contextPath}/student/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                退出登录
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<%@ include file="../common/student-sidebar.jsp" %>

<!-- 主内容区 -->
<div class="content">
    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
            <i class="bi bi-exclamation-triangle"></i> ${error}
        </div>
    </c:if>

    <!-- 搜索区域 -->
    <div class="card">
        <div class="card-header">
            <h5><i class="bi bi-search me-2"></i>搜索课程</h5>
        </div>
        <div class="card-body">
            <form method="get" action="${pageContext.request.contextPath}/student/my-courses" class="search-bar">
                <input type="text" class="form-control" name="nameSearch"
                       value="${nameSearch}" placeholder="请输入课程名称进行搜索">
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-search me-1"></i>搜索
                </button>
                <button type="button" class="btn btn-outline-secondary" onclick="resetSearch()">
                    <i class="bi bi-arrow-clockwise me-1"></i>重置
                </button>
            </form>
        </div>
    </div>

    <!-- 选课列表 -->
    <div class="card">
        <div class="card-header">
            <h5><i class="bi bi-bookmark-check me-2"></i>我的选课</h5>
        </div>
        <div class="card-body">
            <c:choose>
                <c:when test="${not empty courseSelections}">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th style="width: 80px;">序号</th>
                                <th style="width: 200px;">课程名称</th>
                                <th style="width: 150px;">上课时间</th>
                                <th style="width: 120px;">授课教师</th>
                                <th style="width: 80px;">学分</th>
                                <th style="width: 100px;">选课状态</th>
                                <th style="width: 120px;">选课时间</th>
                                <th style="width: 100px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${courseSelections}" var="selection" varStatus="status">
                                <tr>
                                    <td>${(currentPage - 1) * pageSize + status.index + 1}</td>
                                    <td style="text-align: left; font-weight: 500;">
                                        <c:choose>
                                            <c:when test="${not empty selection.course.name}">
                                                ${selection.course.name}
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">未知课程</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty selection.course.courseScheduleList}">
                                                <c:forEach var="schedule" items="${selection.course.courseScheduleList}" varStatus="scheduleStatus">
                                                    <c:if test="${!scheduleStatus.first}"><br/></c:if>
                                                    周${schedule.weekday} 第${schedule.period}节
                                                </c:forEach>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">未安排</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty selection.course.teacher and not empty selection.course.teacher.user.realName}">
                                                ${selection.course.teacher.user.realName}
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">未分配</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty selection.course.credits}">
                                                ${selection.course.credits}
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">--</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${selection.status == 0}">
                                                <span class="status-badge status-pending">待审核</span>
                                            </c:when>
                                            <c:when test="${selection.status == 1}">
                                                <span class="status-badge status-approved">已选课</span>
                                            </c:when>
                                            <c:when test="${selection.status == 2}">
                                                <span class="status-badge status-rejected">已拒绝</span>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">未知状态</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty selection.createTime}">
                                                <c:choose>
                                                    <c:when test="${selection.createTime.length() >= 16}">
                                                        ${selection.createTime.substring(5, 16)}
                                                    </c:when>
                                                    <c:otherwise>
                                                        ${selection.createTime}
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">--</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:if test="${selection.status == 1}">
                                            <button type="button" class="btn btn-warning btn-sm me-2"
                                                    data-course-id="${selection.course.id}" 
                                                    data-course-name="${selection.course.name}"
                                                    onclick="showEvaluationModal(this)">
                                                <i class="bi bi-star me-1"></i>评教
                                            </button>
                                            <button type="button" class="btn btn-danger btn-sm"
                                                    onclick="dropCourse(${selection.course.id})">
                                                <i class="bi bi-x-circle me-1"></i>退课
                                            </button>
                                        </c:if>
                                        <c:if test="${selection.status == 0}">
                                            <span class="text-muted">等待审核</span>
                                        </c:if>
                                        <c:if test="${selection.status == 2}">
                                            <span class="text-muted">已拒绝</span>
                                        </c:if>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页 -->
                    <c:if test="${totalPages > 1}">
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <li class="page-item ${currentPage == 1 ? 'disabled' : ''}">
                                    <a class="page-link" href="?page=${currentPage - 1}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>">
                                        <i class="bi bi-chevron-left"></i> 上一页
                                    </a>
                                </li>

                                <c:forEach begin="1" end="${totalPages}" var="i">
                                    <c:if test="${i == currentPage || (i >= currentPage - 2 && i <= currentPage + 2)}">
                                        <li class="page-item ${i == currentPage ? 'active' : ''}">
                                            <a class="page-link" href="?page=${i}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>">${i}</a>
                                        </li>
                                    </c:if>
                                </c:forEach>

                                <li class="page-item ${currentPage == totalPages ? 'disabled' : ''}">
                                    <a class="page-link" href="?page=${currentPage + 1}&size=${pageSize}<c:if test='${not empty nameSearch}'>&nameSearch=${nameSearch}</c:if>">
                                        下一页 <i class="bi bi-chevron-right"></i>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </c:if>

                    <div class="mt-3 text-muted">
                        <small>共 ${totalRecords} 条记录</small>
                    </div>
                </c:when>
                <c:otherwise>
                    <div class="empty-state">
                        <i class="bi bi-bookmark-check"></i>
                        <h5>暂无选课记录</h5>
                        <p class="text-muted">您还没有选择任何课程，请前往课程管理进行选课。</p>
                        <a href="${pageContext.request.contextPath}/student/courses" class="btn btn-primary">
                            <i class="bi bi-plus-circle me-1"></i>去选课
                        </a>
                    </div>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</div>

<!-- 个人信息模态框 -->
<div class="modal fade" id="profileModal" tabindex="-1" aria-labelledby="profileModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="border-radius: 12px;">
            <div class="modal-header" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 12px 12px 0 0;">
                <h5 class="modal-title" id="profileModalLabel">
                    <i class="bi bi-person-circle"></i> 个人信息
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding: 30px;">
                <c:if test="${not empty currentStudent}">
                    <div class="row mb-4">
                        <div class="col-12 text-center">
                            <div style="width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; color: white; font-size: 2rem;">
                                <i class="bi bi-person-circle"></i>
                            </div>
                            <h5 class="mb-1">
                                <c:choose>
                                    <c:when test="${not empty currentStudent.user.realName}">
                                        ${currentStudent.user.realName}
                                    </c:when>
                                    <c:otherwise>
                                        学生信息
                                    </c:otherwise>
                                </c:choose>
                            </h5>
                            <p class="text-muted mb-0">学生个人信息详情</p>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person me-2"></i>姓名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.realName}">
                                            ${currentStudent.user.realName}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-card-text me-2"></i>学号</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.studentNo}">
                                            ${currentStudent.studentNo}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person-badge me-2"></i>用户名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.username}">
                                            ${currentStudent.user.username}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-gender-ambiguous me-2"></i>性别</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${currentStudent.gender == 1}">
                                            <span class="badge" style="background: #e3f2fd; color: #1976d2;">男</span>
                                        </c:when>
                                        <c:when test="${currentStudent.gender == 0}">
                                            <span class="badge" style="background: #fce4ec; color: #e91e63;">女</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-building me-2"></i>班级</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.name}">
                                            ${currentStudent.clazz.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-mortarboard me-2"></i>专业</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.name}">
                                            ${currentStudent.clazz.major.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-bank me-2"></i>学院</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.college and not empty currentStudent.clazz.major.college.name}">
                                            ${currentStudent.clazz.major.college.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配学院</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-envelope me-2"></i>电子邮箱</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.email}">
                                            ${currentStudent.email}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-telephone me-2"></i>联系电话</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.phone}">
                                            ${currentStudent.phone}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>
                
                <c:if test="${empty currentStudent}">
                    <div class="text-center py-5">
                        <i class="bi bi-exclamation-circle text-warning" style="font-size: 3rem;"></i>
                        <h5 class="mt-3">无法获取学生信息</h5>
                        <p class="text-muted">请联系管理员或重新登录</p>
                    </div>
                </c:if>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                <a href="${pageContext.request.contextPath}/student/changePassword" class="btn" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                    <i class="bi bi-key me-1"></i>修改密码
                </a>
            </div>
        </div>
    </div>
</div>

<!-- 评教模态框 -->
<div class="modal fade" id="evaluationModal" tabindex="-1" aria-labelledby="evaluationModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="border-radius: 12px;">
            <div class="modal-header" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white; border-radius: 12px 12px 0 0;">
                <h5 class="modal-title" id="evaluationModalLabel">
                    <i class="bi bi-star"></i> 课程评价
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding: 30px;">
                <div class="row mb-4">
                    <div class="col-12">
                        <div style="padding: 20px; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); border-radius: 12px; color: white; text-align: center;">
                            <h5 class="mb-2" id="evaluationCourseName">课程名称</h5>
                            <p class="mb-0">请对本课程进行客观公正的评价</p>
                        </div>
                    </div>
                </div>
                
                <form id="evaluationForm">
                    <input type="hidden" id="evaluationCourseId" name="courseId">
                    
                    <!-- 评分项目 -->
                    <div class="row">
                        <div class="col-12 mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-star me-2"></i>教学效果评分
                            </label>
                            <div class="d-flex align-items-center">
                                <div class="rating-stars me-3" data-rating="0" data-field="teachingEffect">
                                    <i class="bi bi-star" data-value="1"></i>
                                    <i class="bi bi-star" data-value="2"></i>
                                    <i class="bi bi-star" data-value="3"></i>
                                    <i class="bi bi-star" data-value="4"></i>
                                    <i class="bi bi-star" data-value="5"></i>
                                </div>
                                <span class="rating-text text-muted">请点击星级评分</span>
                            </div>
                        </div>
                        
                        <div class="col-12 mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-person me-2"></i>教师态度评分
                            </label>
                            <div class="d-flex align-items-center">
                                <div class="rating-stars me-3" data-rating="0" data-field="teacherAttitude">
                                    <i class="bi bi-star" data-value="1"></i>
                                    <i class="bi bi-star" data-value="2"></i>
                                    <i class="bi bi-star" data-value="3"></i>
                                    <i class="bi bi-star" data-value="4"></i>
                                    <i class="bi bi-star" data-value="5"></i>
                                </div>
                                <span class="rating-text text-muted">请点击星级评分</span>
                            </div>
                        </div>
                        
                        <div class="col-12 mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-book me-2"></i>课程内容评分
                            </label>
                            <div class="d-flex align-items-center">
                                <div class="rating-stars me-3" data-rating="0" data-field="courseContent">
                                    <i class="bi bi-star" data-value="1"></i>
                                    <i class="bi bi-star" data-value="2"></i>
                                    <i class="bi bi-star" data-value="3"></i>
                                    <i class="bi bi-star" data-value="4"></i>
                                    <i class="bi bi-star" data-value="5"></i>
                                </div>
                                <span class="rating-text text-muted">请点击星级评分</span>
                            </div>
                        </div>
                        
                        <div class="col-12 mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-chat-dots me-2"></i>评价意见
                            </label>
                            <textarea class="form-control" id="evaluationComment" name="comment" rows="4" 
                                      placeholder="请输入您对本课程的具体意见和建议..."></textarea>
                        </div>
                    </div>
                    
                    <div class="alert alert-info">
                        <i class="bi bi-info-circle me-2"></i>
                        <strong>温馨提示：</strong>您的评价将有助于改善教学质量，请客观公正地进行评价。
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="submitEvaluation()">
                    <i class="bi bi-check-circle me-1"></i>提交评价
                </button>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 用户下拉菜单
    document.getElementById('userDropdownContainer').addEventListener('click', function(e) {
        e.stopPropagation();
        console.log('用户头像区域被点击了 - 我的选课页面');
        const dropdown = document.getElementById('userDropdown');
        
        if (!dropdown) {
            console.error('找不到下拉菜单元素');
            return;
        }
        
        // 先重置状态，确保准确判断
        const computedStyle = window.getComputedStyle(dropdown);
        const isReallyVisible = computedStyle.opacity !== '0' && computedStyle.visibility !== 'hidden' && dropdown.offsetHeight > 0;
        
        console.log('CSS opacity:', computedStyle.opacity);
        console.log('CSS visibility:', computedStyle.visibility);
        console.log('元素高度:', dropdown.offsetHeight);
        console.log('真实显示状态:', isReallyVisible);
        
        if (isReallyVisible) {
            // 隐藏
            dropdown.style.opacity = '0';
            dropdown.style.visibility = 'hidden';
            dropdown.style.transform = 'translateY(-10px)';
            dropdown.classList.remove('show');
            console.log('隐藏下拉菜单');
        } else {
            // 显示
            dropdown.style.opacity = '1';
            dropdown.style.visibility = 'visible';
            dropdown.style.transform = 'translateY(0)';
            dropdown.classList.add('show');
            console.log('显示下拉菜单');
        }
    });

    // 点击其他地方关闭下拉菜单
    document.addEventListener('click', function() {
        const dropdown = document.getElementById('userDropdown');
        if (dropdown) {
            dropdown.style.opacity = '0';
            dropdown.style.visibility = 'hidden';
            dropdown.style.transform = 'translateY(-10px)';
        dropdown.classList.remove('show');
        }
    });
    
    // 重置搜索
    function resetSearch() {
        window.location.href = '${pageContext.request.contextPath}/student/my-courses';
    }

    // 退课功能
    function dropCourse(courseId) {
        if (!confirm('确定要退选这门课程吗？退课后将从您的选课列表中移除。')) {
            return;
        }

        fetch('${pageContext.request.contextPath}/student/courses/drop', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: 'courseId=' + courseId
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                alert(data.message || '退课成功！');
                location.reload();
            } else {
                alert('退课失败：' + (data.message || '未知错误'));
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('发生错误，请稍后再试！');
        });
    }

    // 显示个人信息模态框
    function showProfileModal() {
        // 关闭用户下拉菜单
        const dropdown = document.getElementById('userDropdown');
        if (dropdown) {
            dropdown.style.opacity = '0';
            dropdown.style.visibility = 'hidden';
            dropdown.style.transform = 'translateY(-10px)';
        dropdown.classList.remove('show');
        }
        
        // 显示模态框
        const modal = new bootstrap.Modal(document.getElementById('profileModal'));
        modal.show();
    }

    // 显示评教模态框
    function showEvaluationModal(button) {
        const courseId = button.getAttribute('data-course-id');
        const courseName = button.getAttribute('data-course-name');
        
        // 设置课程信息
        document.getElementById('evaluationCourseId').value = courseId;
        document.getElementById('evaluationCourseName').textContent = courseName;
        
        // 重置表单
        resetEvaluationForm();
        
        // 显示模态框
        const modal = new bootstrap.Modal(document.getElementById('evaluationModal'));
        modal.show();
    }

    // 重置评教表单
    function resetEvaluationForm() {
        // 重置所有星级评分
        document.querySelectorAll('.rating-stars').forEach(ratingContainer => {
            ratingContainer.setAttribute('data-rating', '0');
            ratingContainer.querySelectorAll('i').forEach(star => {
                star.classList.remove('active');
            });
        });
        
        // 重置评价意见
        document.getElementById('evaluationComment').value = '';
        
        // 重置提示文本
        document.querySelectorAll('.rating-text').forEach(text => {
            text.textContent = '请点击星级评分';
            text.className = 'rating-text text-muted';
        });
    }

    // 初始化星级评分事件
    document.addEventListener('DOMContentLoaded', function() {
        // 为每个星级评分容器添加事件监听
        document.querySelectorAll('.rating-stars').forEach(ratingContainer => {
            const stars = ratingContainer.querySelectorAll('i');
            const ratingText = ratingContainer.parentElement.querySelector('.rating-text');
            
            stars.forEach((star, index) => {
                // 点击事件
                star.addEventListener('click', function() {
                    const rating = parseInt(star.getAttribute('data-value'));
                    ratingContainer.setAttribute('data-rating', rating);
                    
                    // 更新星级显示
                    stars.forEach((s, i) => {
                        if (i < rating) {
                            s.classList.add('active');
                        } else {
                            s.classList.remove('active');
                        }
                    });
                    
                    // 更新提示文本
                    const ratingTexts = ['很差', '较差', '一般', '较好', '很好'];
                    ratingText.textContent = ratingTexts[rating - 1] + ' (' + rating + '分)';
                    ratingText.className = 'rating-text text-warning fw-bold';
                });
                
                // 鼠标悬停效果
                star.addEventListener('mouseenter', function() {
                    const rating = parseInt(star.getAttribute('data-value'));
                    stars.forEach((s, i) => {
                        if (i < rating) {
                            s.style.color = '#ffc107';
                        } else {
                            s.style.color = '#ddd';
                        }
                    });
                });
            });
            
            // 鼠标离开时恢复选中状态
            ratingContainer.addEventListener('mouseleave', function() {
                const currentRating = parseInt(ratingContainer.getAttribute('data-rating'));
                stars.forEach((s, i) => {
                    if (i < currentRating) {
                        s.style.color = '#ffc107';
                    } else {
                        s.style.color = '#ddd';
                    }
                });
            });
        });
    });

    // 提交评教
    function submitEvaluation() {
        const courseId = document.getElementById('evaluationCourseId').value;
        const comment = document.getElementById('evaluationComment').value;
        
        // 获取各项评分
        const teachingEffect = parseInt(document.querySelector('[data-field="teachingEffect"]').getAttribute('data-rating'));
        const teacherAttitude = parseInt(document.querySelector('[data-field="teacherAttitude"]').getAttribute('data-rating'));
        const courseContent = parseInt(document.querySelector('[data-field="courseContent"]').getAttribute('data-rating'));
        
        // 验证评分
        if (teachingEffect === 0 || teacherAttitude === 0 || courseContent === 0) {
            alert('请完成所有项目的评分！');
            return;
        }
        
        // 计算平均分
        const averageScore = ((teachingEffect + teacherAttitude + courseContent) / 3).toFixed(1);
        
        // 提交评教数据
        const formData = new FormData();
        formData.append('courseId', courseId);
        formData.append('teachingEffect', teachingEffect);
        formData.append('teacherAttitude', teacherAttitude);
        formData.append('courseContent', courseContent);
        formData.append('averageScore', averageScore);
        formData.append('comment', comment);
        
        fetch('${pageContext.request.contextPath}/student/evaluation/submit', {
            method: 'POST',
            body: formData
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                alert('评教提交成功！感谢您的评价。');
                // 关闭模态框
                const modal = bootstrap.Modal.getInstance(document.getElementById('evaluationModal'));
                modal.hide();
            } else {
                alert('评教提交失败：' + (data.message || '未知错误'));
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('提交失败，请稍后再试！');
            });
    }
</script>
</body>
</html>